package code.example.zookeeper.master;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.leader.LeaderLatch;
import org.apache.curator.framework.recipes.leader.LeaderLatchListener;
import org.apache.curator.retry.ExponentialBackoffRetry;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Created by yanlei on 2017/6/9.
 */
public class ZookeeperClientTest {

    public void test(final  String  id){


             ZookpeerConfig config = new ZookpeerConfig();
            config.setNamespace("Tcc");
            config.setConnectString("172.17.5.81:2181");
             ZookeeperClient client = new ZookeeperClient();
            client.setZookpeerConfig(config);
            client.leaderLatch("/helloxxdd",id ,new LeaderLatchListener(){
                @Override
                public void isLeader() {
                    System.out.println(id +" is leader");
                }

                @Override
                public void notLeader() {
                    System.out.println(id +" is not leader");
                }
            });

    }
    public static void main(String args []){


        new ZookeeperClientTest().test("3");
        try {
            TimeUnit.SECONDS.sleep(10000);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
